package com.fengzhilian.timewheel;

import com.fengzhilian.timewheel.container.Bucket;
import com.fengzhilian.timewheel.container.DelayQueue;
import com.fengzhilian.timewheel.task.CustomerTasker;
import com.fengzhilian.timewheel.task.TestTasker;
import com.fengzhilian.timewheel.task.TimedTask;
import com.fengzhilian.timewheel.wheel.TimeWheel;
import com.fengzhilian.timewheel.util.TimeWheelUtil;

import java.util.Date;

/**
 * 测试
 */
public class MainTest {
    /**
     * 针对天，周，月，年,以及甲子年轮进行测试
     * @param args
     * @throws Exception
     */
    public static  void main(String[] args) throws Exception {

        //天轮测试
        TimeWheelUtil.getInstance().initTimeWheel("first",TimeWheel.TIME_WHEEL_TYPE_DAY);
        for (int i=1;i<=10;i++) {
            TimedTask t =new TestTasker();
            t.setExpireTimestamp(System.currentTimeMillis()+(i*4000));
            TimeWheelUtil.getInstance().addTaskAndCommit("first",t);
        }
        //周轮测试

        TimeWheelUtil.getInstance().initTimeWheel("second", TimeWheel.TIME_WHEEL_TYPE_WEEK);
        for (int i=1;i<=20;i++) {
            TimedTask t =new TestTasker();
            t.setExpireTimestamp(System.currentTimeMillis()+(i*6000));
            TimeWheelUtil.getInstance().addTaskAndCommit("second",t);
        }
        //月轮测试
        TimeWheelUtil.getInstance().initTimeWheel("third", TimeWheel.TIME_WHEEL_TYPE_MONTH);
        for (int i=1;i<=30;i++) {
            TimedTask t =new TestTasker();
            t.setExpireTimestamp(System.currentTimeMillis()+(i*1000));
            TimeWheelUtil.getInstance().addTaskAndCommit("third",t);
        }
        //年轮测试
        TimeWheelUtil.getInstance().initTimeWheel("forth",TimeWheel.TIME_WHEEL_TYPE_YEAR);
        for (int i=1;i<=40;i++) {
            TimedTask t =new TestTasker();
            t.setExpireTimestamp(System.currentTimeMillis()+(i*3000));
            TimeWheelUtil.getInstance().addTaskAndCommit("forth",t);
        }
        //甲子年轮测试
        TimeWheelUtil.getInstance().initTimeWheel("fifth",TimeWheel.TIME_WHEEL_TYPE_SIXTY_YEAR);
        for (int i=1;i<=40;i++) {
            TimedTask t =new CustomerTasker(System.nanoTime()+"",new Date());
            t.setExpireTimestamp(System.currentTimeMillis()+(i*3000));
            TimeWheelUtil.getInstance().addTaskAndCommit("fifth",t);
        }

    }

}
